import json
import cv2
from cgi import test
from cv2 import mean
from importlib_metadata import distribution, re
# from matplotlib.pyplot import step
import numpy as np
import math
import time
import sys
import os
import argparse
from colorama import Fore, Back, Style
from colorama import init

# read the json file into a python array
def read_json(json_file):
    with open(json_file, 'r') as f:
        data = json.load(f)
    return data

# convert data to a 1D flat array
def flatten_json(data):
    flat_data = []
    for i in data:
        for j in i:
            for k in j:
                flat_data.append(k)
    return flat_data

# traverse every json file in the current directory
def traverse_json(json_dir):
    json_files = []
    for root, dirs, files in os.walk(json_dir):
        for file in files:
            if file.endswith('.json'):
                # print(file)
                json_files.append(file)
                # json_files.append(os.path.join(root, file))
    return json_files

j_files = traverse_json("./")

for j_file in j_files:
    data = read_json(j_file)
    flat_data = flatten_json(data)
    j_string = "{\"data\":" + json.dumps(flat_data) + "}"
    with open(j_file, "w") as f:
        f.write(j_string)
    print(j_string)
